package com.ce.pms.log4ce;

import java.util.Collection;
import java.util.Map;

import org.aspectj.lang.JoinPoint;

import com.ce.common.util.BlankUtil;
import com.ce.component.log4ce.aop.constructor.support.AbstractBizDescriptionHandler;
import com.ce.component.log4ce.aop.constructor.support.BizDescriptionHandler;
import com.ce.component.log4ce.aop.parser.BizLogParser;
import com.ce.pms.customer.vo.MoveVO;
import com.ce.pms.customer.vo.MoveVO.Possessor;

public class CustomerMovingHandler extends AbstractBizDescriptionHandler implements BizDescriptionHandler {

	private Log4ceHelper log4ceHelper = Log4ceHelper.getInstance();
	@Override
	public Map<String, Object> getNamedParametersMap(JoinPoint joinPoint, Object obj, BizLogParser logParser) {

		Map<String,Object> map = logParser.getLogArguments(joinPoint);

		//获取被代理方法的参数
		MoveVO moveVO = (MoveVO) map.get("moveVO");

		//所入住的房号。
		Map mapHouse = moveVO.getHouses();
		String hnsStr = log4ceHelper.mapValuesToString(mapHouse);

		//所入住的人
		Map mapCustomer = moveVO.getOwnerOrLessee();
		Collection<Possessor> poss = mapCustomer.values();
		StringBuffer cmStr = new StringBuffer();
		if(!BlankUtil.isBlank(poss))
		{
			Possessor [] possObjs = new Possessor[]{};
			possObjs = poss.toArray(possObjs);
			for(int i = 0; i < possObjs.length; i++)
			{
				Possessor possessor = possObjs[i];
				cmStr.append(possessor.getName());
				String memberStr = log4ceHelper.mapValuesToString(possessor.getMembers());
				if(!BlankUtil.isBlank(memberStr)){
					cmStr.append(",").append(memberStr);
				}
				if(i<possObjs.length-1)
				{
					cmStr = cmStr.append(",");
				}
			}
		}

		map.put("houseNumber", hnsStr);
		map.put("customers", cmStr.toString());
		map.put("date", moveVO.getMoveDate());

		map.putAll(logParser.getLogStaticContents(joinPoint));

		return map;
	}
}
